import { defineStore } from "pinia";
import AvatarImg from "../assets/user.png";

interface UserType {
  id: number;
  name: string;
  token: string
  work?: string;
  avatar?: string;
}

export const useUser = defineStore("user", {
  state: () => ({
    user: {
      id: 110,
      name: "susan007",
      work: "farmer",
      avatar: AvatarImg,
      token: "test123"
    } as UserType,
  }), // 属性
  getters: {
    // getUser: (state) => state // 计算属性
  },
  actions: { // 方法
    getUser() {
      return this.user;
    },
    setUser(newUser: UserType) {
      this.user = { ...newUser };
    },
  },
});
